package com.gwd.task.services.impl;

import com.gwd.task.services.FileLoadServer;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.UUID;

/**
 * @author zhiyongming
 * @date 2020/12/11 16:09
 */
@Service
public class FileLoadServerImpl implements FileLoadServer {
    @Override
    public String upLoadFile(MultipartFile file) {
        String path = "E:\\files\\";
        String fileName = UUID.randomUUID().toString().replace("-", "");
        File targetFile = new File(path + fileName);

        FileOutputStream fo;
        try {
            fo = new FileOutputStream(targetFile);
            fo.write(file.getBytes());
            fo.flush();
            fo.close();
        } catch (IOException e) {
            return "";
        }

        return fileName;
    }
}
